package wili.b1;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import wili.c.Ca;

public interface DocKinds {// "([^"]+)" : ("[^"]+"),
	Item ORPC = new Item("ORPC", "A/P Credit Memos@1002", 999);
	Item OITM = new Item("OITM", "Items@1002", 999);
	Item OINS = new Item("OINS", "Equipment Card@1001", 999);
	Item OPRJ = new Item("OPRJ", "Project Codes@1001", 999);
	Item OITT = new Item("OITT", "Bills of Materials@1002", 999);
	Item OVPM = new Item("OVPM", "Outgoing Payments", 999);
	Item OWTM = new Item("OWTM", "Approval Templates", 999);
	Item OPRR = new Item("OPRR", "Goods Return Request", 999);
	Item OPRQ = new Item("OPRQ", "Purchase Request", 999);
	Item ORRR = new Item("ORRR", "Return Requests", 999);
	Item OOPR = new Item("OOPR", "Opportunities", 999);
	Item OINV = new Item("OINV", "A/R Invoices", 999);
	Item ORDN = new Item("ORDN", "Returns", 999);
	Item OSLT = new Item("OSLT", "Solutions Knowledge Base", 999);
	Item OWDD = new Item("OWDD", "Docs in Approval Process", 999);
	Item OJDT = new Item("OJDT", "Journal Entries", 999);
	Item OWHS = new Item("OWHS", "Warehouse", 999);
	Item ORSC = new Item("ORSC", "Resources", 999);
	Item ORSB = new Item("ORSB", "Resource Groups", 999);
	Item OIGE = new Item("OIGE", "Goods Issues", 999);// 60
	Item OPQT = new Item("OPQT", "Purchase Quotations", 999);
	Item OPOR = new Item("OPOR", "Purchase Orders", 999);
	Item ORST = new Item("ORST", "Route Stages", 999);
	Item OCRD = new Item("OCRD", "Business Partners", 999);
	Item OPCH = new Item("OPCH", "A/P Invoices", 999);
	Item OQUT = new Item("OQUT", "Sales Quotations", 999);
	Item OIGN = new Item("OIGN", "Goods Receipts", 999);
	Item OSCL = new Item("OSCL", "Service Calls", 999);
	Item OMRC = new Item("OMRC", "Manufacturers", 999);
	Item OCLG = new Item("OCLG", "Activities", 999);
	Item OLCT = new Item("OLCT", "Location", 999);
	Item OWST = new Item("OWST", "Approval Stages", 999);
	Item ORIN = new Item("ORIN", "A/R Credit Memos", 999);
	Item ODRF = new Item("ODRF", "Sales & Purchasing Drafts", 112);
	Item OITB = new Item("OITB", "Item Groups", 999);
	Item OWOR = new Item("OWOR", "Production Order", 999);
	Item ORCT = new Item("ORCT", "Incoming Payments", 999);
	Item ORPD = new Item("ORPD", "Goods Returns", 999);
	Item ODLN = new Item("ODLN", "Deliveries", 999);
	Item VOIGNP = new Item("VOIGNP", "", 1006);

	static class Item {
		long id;
		String key, name;

		public String toString() {
			if ("".isEmpty())
				return name;
			return key + ":" + name + ":" + id;
		}

		public Item(String key, String name, long id) {
			this.key = key;
			this.name = name;
			this.id = id;
		}
	}

	interface SalcesDoc {//'(-10000|13|14|15|16|17|23|234000031)'
		// String (\w+) = "[^"]+";
		Item OQUT = new Item("OQUT", "Sales Quotations", 23);
		Item ORDR = new Item("ORDR", "Sales Orders", 17);
		Item OINV = new Item("OINV", "A/R Invoices", 13);//Accounts receivable
		Item OINV_RV = new Item("OINV_RV", "A/R Reserve Invoices", -10000);
		Item ODLN = new Item("ODLN", "Deliveries", 15);
		Item ORRR = new Item("ORRR", "Return Requests", 234000031);
		Item ORDN = new Item("ORDN", "Returns", 16);// ````````````````````
		Item ORIN = new Item("ORIN", "A/R Credit Memos", 14);
		// String msg = "ODLN:Deliveries:15, OINV:A/R Invoices:13, OINV_RV:A/R Reserve
		// Invoices:-10000, OQUT:Sales Quotations:23, ORDN:Returns:16, ORDR:Sales
		// Orders:17, ORIN:A/R Credit Memos:14, ORRR:Return Requests:234000031";
	}

	interface PurchaseDoc {
		//'(540000006|1470000113|22|18|-10001|59|20|21|19|234000032)'
		Item OPQT = new Item("OPQT", "Purchase Quotations", 540000006);
		Item OPRQ = new Item("OPRQ", "Purchase Request", 1470000113);
		Item OPOR = new Item("OPOR", "Purchase Orders", 22);
		Item OPCH = new Item("OPCH", "A/P Invoices", 18);//account payable, 应付发票，Accounts payable应付帐款
		Item OPCH_RV = new Item("OPCH_RV", "A/P Reserve Invoice", -10001);//应付预留发票
		//
		Item OIGN = new Item("OIGN", "Goods Receipts", 59);
		Item OPDN = new Item("OPDN", "Goods Receipt POs", 20);
		Item ORPD = new Item("ORPD", "Goods Returns", 21);
		Item OPRR = new Item("OPRR", "Goods Return Request", 234000032);// OPRR
		Item ORPC = new Item("ORPC", "A/P Credit Memos", 19);
		// String msg = "OIGN:Goods Receipts:59, OPCH:A/P Invoices:18, OPCH_RV:A/P
		// Reserve Invoice:-10001, OPDN:Goods Receipt POs:20, OPOR:Purchase Orders:22,
		// OPQT:Purchase Quotations:540000006, OPRQ:Purchase Request:1470000113,
		// OPRR:Goods Return Request:234000032, ORPC:A/P Credit Memos:19, ORPD:Goods
		// Returns:21";
	}

	static void printMarketingDoc_orderById() {
		/*
		 * -10001:OPCH_RV:A/P Reserve Invoice:-10001 18:OPCH:A/P Invoices:18 19:ORPC:A/P
		 * Credit Memos:19 20:OPDN:Goods Receipt POs:20 21:ORPD:Goods Returns:21
		 * 22:OPOR:Purchase Orders:22 59:OIGN:Goods Receipts:59 234000032:OPRR:Goods
		 * Return Request:234000032 540000006:OPQT:Purchase Quotations:540000006
		 * 1470000113:OPRQ:Purchase Request:1470000113
		 */
		Method[] mm = PurchaseDoc.class.getMethods();
		Class[] cc = { SalcesDoc.class, PurchaseDoc.class };
		//
		Class c = cc[0];
		Field[] ff = c.getFields();
		List<Item> list = new ArrayList<>();
		for (Field fd : ff) {
			try {
				list.add((Item) fd.get(c));
			} catch (IllegalAccessException e) {
				throw new RuntimeException(e);
			}
		}
		StringBuilder sb = new StringBuilder();
		Collections.sort(list, new Comparator<Item>() {
			@Override
			public int compare(Item o1, Item o2) {
				return (int) (o1.id - o2.id);
			}
		});
		for (Item item : list) {
			sb.append("\n" + item.toString());
		}
		Ca.log(sb.toString());
	}

	public static void main(String[] args) {//b1 js中，页面值是取自函数还是属性？
		printMarketingDoc_orderById();
	}
}
